#coding:utf-8
#将爬取的数据进行存储
class HtmlOutputer(object):
    def __init__(self):
        self.datas=[]
    # 手机数据
    def collect_data(self,data):
        if data is None:
            return
        self.datas.append(data)

    # 输出展示数据--------------这里修改成保存数据库
    def output_html(self):
        font = open('output.html','w',encoding='utf-8')
        font.write('<html><head><meta charset="utf-8" /></head>')
        font.write('<body>')
        font.write('<table border="1">')

        for data in self.datas:
            font.write('<tr>')
            font.write("<td>%s</td>" % data['url'])
            #data['title'].encode('utf-8').decode()这里先encode后decode需要进一步找原因
            font.write("<td>%s</td>" % data['title'].encode('utf-8').decode())
            font.write("<td>%s</td>" % data['summary'].encode('utf-8').decode())
            font.write('</tr>')

        font.write('</table>')
        font.write('</body>')
        font.write('</html>')
        font.close()

